package com.google.appengine.guoxufeng;

import java.io.IOException;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.appspot.guoxufeng.domain.User;

@SuppressWarnings("serial")
public class guoxufengServlet extends HttpServlet {
	
	private static final EntityManagerFactory emfInstance = Persistence
	.createEntityManagerFactory("transactions-optional");
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/plain");
		resp.getWriter().println("Hello, world");
		
		EntityManager em =emfInstance.createEntityManager();
		List l=em.createQuery("select u from com.appspot.guoxufeng.domain.User u where u.name='test'").getResultList();
		resp.getWriter().println(l.size());
		for (Object u:l){
			resp.getWriter().println(((User)u).getName());
		}
		
		em.close();

	}
}
